<template>
  <div class="avue-logo">
    <transition name="fade">
      <span v-if="keyCollapse"
            class="avue-logo_subtitle"
            key="0">
        {{ website.logo }}
      </span>
    </transition>
    <transition-group name="fade">
        <template v-if="!keyCollapse">
          <span class="avue-logo_title"
                key="1">
                <div v-if="!oc">
                  <div v-if="this.icBtn===false">{{ website.indexTitle }}</div>
                  <div v-else class="oc_logo">
                      <div class="business">
                          商务</br>中心
                      </div>
                      <div class="oc_change">
                          <img src="/img/icon/change.png" alt="">
                      </div>
                      <div class="offer">
                         <a href="javascript:void(0)" class=".a_post" @click="openIcPage()"> 智能</br>素材</a>
                      </div>
                  </div>
                </div>
                
                <div v-else class="oc_logo">
                  <div class="offer">
                    订单</br>中心
                  </div>
                  <div class="oc_change">
                    <img src="/img/icon/change.png" alt="">
                  </div>
                  <div class="business" @click="jump">
                    商务</br>中心
                  </div>
                </div>
                <div newPageLink></div>
          </span>
        </template>
    </transition-group>
  </div>
</template>

<script>
import {mapGetters} from "vuex";
import {BC_LOGIN_URL,IC_LOGIN_URL} from "@/const/urlConst";

export default {
  name: "logo",
  data() {
    return {
        icBtn : false
    };
  },
  watch: {
    oc: {
      deep: true,
      handler(val) {
        this.updateTitle(val);
      }
    }
  },
  created() {
    this.updateTitle(this.oc);
    let roles = this.userInfo.role_name.split(',')
      roles.forEach(item=>{
          if(item ==='ic_designer'){
              this.icBtn=true
          }
      })
  },
  computed: {
    ...mapGetters(["website", "keyCollapse", "oc","userInfo"])
  },
  methods: {
    updateTitle(isOC) {
      if (isOC == false) {
        this.website.indexTitle = '商务中心';
      } else {
        this.website.indexTitle = '订单中心';
      }
    },
    jump() {
      let str = BC_LOGIN_URL
      window.open(str.substring(0, str.lastIndexOf('/')))
    },
    openIcPage(){
        let eleList = document.querySelectorAll('div[newPageLink]');
        let content = eleList[0];
        let linkEle = document.createElement("a");
        content.appendChild(linkEle);
        let icData=JSON.parse(localStorage.getItem("saber-userInfo")); 
        let data=JSON.stringify(icData.content)
      //   利用URL.createObjectURL()方法为a元素生成blob URL
        linkEle.target = '_blank';
        linkEle.href = IC_LOGIN_URL + '?data=' + data;
        linkEle.click();
        linkEle.remove();
      }
    }
  
};
</script>

<style lang="scss" scoped>
.oc_logo {
  justify-content: center;
  align-items: center;
  padding-bottom: 2px;
  position: fixed;
  display: flex;
  top: 0;
  left: 0;
  width: 200px;
  height: 63px;
  line-height: 64px;

  .offer {
    cursor: pointer;
    font-size: 12px;
    line-height: 15px;
    background: #1684fd;
    width: 55px;
    height: 55px;
    border-radius: 50%;
    color: white;
    display: flex;
    flex-direction: column;
    text-align: center;
    align-items: center;
    justify-content: center;

    div {
      height: 18px;
    }
    a{
          color: #fff;
      }
  }

  .oc_change {
    width: 20px;
    padding: 0 10px;

    img {
      width: 100%;
      height: auto;
    }
  }

  .business {
    cursor: pointer;
    height: 50px;
    font-size: 13px;
    background: #FFB154;
    width: 50px;
    border-radius: 50%;
    color: white;
    display: flex;
    line-height: 15px;
    flex-direction: column;
    text-align: center;
    align-items: center;
    justify-content: center;
    div {
      height: 18px;
    }
  }
}

.fade-leave-active {
  transition: opacity 0.2s;
}

.fade-enter-active {
  transition: opacity 2.5s;
}

.fade-enter,
.fade-leave-to {
  opacity: 0;
}

.avue-logo {
  position: fixed;
  top: 0;
  left: 0;
  width: 200px;
  height: 64px;
  line-height: 64px;
  background-color: #20222a;
  font-size: 20px;
  overflow: hidden;
  box-sizing: border-box;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.15);
  color: rgba(255, 255, 255, 0.8);
  z-index: 1024;

  &_title {
    display: block;
    text-align: center;
    font-weight: 300;
    font-size: 20px;
  }

  &_subtitle {
    display: block;
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #fff;
  }
}
</style>
